﻿<html>
<head>
    <title>显示列设置</title>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString2016.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script src="../Gener.js?va2=2" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script type="text/javascript">

        //页面启动函数.
        $(function () {

            var ensName = GetQueryString("EnsName");

            //全局配置.
            var en = new Entity("BP.Sys.EnCfg");
            en.No = ensName;
            en.Retrieve();

            //获得该实体的列.
            //var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");

            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", ensName, "Idx");
            if (mapAttrs.length == 0) {

                var hander = new HttpHandler("BP.WF.HttpHandler.WF_Admin_FoolFormDesigner");
                hander.Clear();
                hander.AddPara("IsFirst", 1);
                hander.AddPara("FK_MapData", ensName);
                hander.AddPara("FK_Flow", GetQueryString("FK_Flow"));
                hander.AddPara("FK_Node", GetQueryString("FK_Node"));
                var data = hander.DoMethodReturnString("Designer_Init");
                mapAttrs.Retrieve("FK_MapData", ensName, "Idx");
            }

            //alert("请启动傻瓜表单设计器");


            for (var i = 0; i < mapAttrs.length; i++) {

                var mapAttr = mapAttrs[i];
                if (mapAttr.KeyOfEn == 'OID') {
                    continue;
                }

                var mapAttrEn = new Entity("BP.Sys.MapAttr", mapAttr);

                var html = "";
                html += "<tr>";
                html += "<td>" + i + "</td>";
                html += "<td>" + mapAttr.KeyOfEn + "</td>";

                html += "<td> <input value='" + mapAttr.Name + "' type=text style='width:100%;'  id='TB_" + mapAttr.KeyOfEn + "' /></td>";
                html += "<td> <input value='" + mapAttr.UIWidth + "' type=text style='width:40px;'  id='TBW_" + mapAttr.KeyOfEn + "' /></td>";

                if (mapAttrEn.GetPara("SearchVisable") == "1")
                    html += "<td><a  href=\"javascript:HiddenIt('" + mapAttr.MyPK + "')\">隐藏</a></td>";
                else
                    html += "<td style='text-align:right' ><a href=\"javascript:ShowIt('" + mapAttr.MyPK + "')\">显示</a></td>";

                html += "<td><a href=\"javascript:Up('" + mapAttr.MyPK + "')\">上移</a> - <a href=\"javascript:Down('" + mapAttr.MyPK + "')\">下移</a></td>";
                html += "</tr>";

                $("#Table1 tr:last").after(html);
            }

        });

        function HiddenIt(mypk, i) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.SetPara("SearchVisable", 0);
            mapAttrEn.Update();

            window.location.href = window.location.href;
        }

        function ShowIt(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.SetPara("SearchVisable", 1);
            mapAttrEn.Update();
            window.location.href = window.location.href;
        }

        function Up(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.DoMethodReturnString("DoUpTabIdx");
            window.location.href = window.location.href;
        }
        function Down(mypk) {
            var mapAttrEn = new Entity("BP.Sys.MapAttr", mypk);
            mapAttrEn.DoMethodReturnString("DoDownTabIdx");

            window.location.href = window.location.href;
        }

        function SaveCols() {

            var ensName = GetQueryString("EnsName");
            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", ensName, "Idx");

            for (var i = 0; i < mapAttrs.length; i++) {

                var mapAttr = mapAttrs[i];
                if (mapAttr.KeyOfEn == 'OID') {
                    continue;
                }

                var mapAttrEn = new Entity("BP.Sys.MapAttr", mapAttr);

                mapAttrEn.Name = $("#TB_" + mapAttrEn.KeyOfEn).val();
                mapAttrEn.UIWidth = $("#TBW_" + mapAttrEn.KeyOfEn).val();
                mapAttrEn.Update();

            }

            window.location.href = window.location.href;
        }

        function Back() {
            var url = "SearchSetting.htm?EnsName=" + GetQueryString("EnsName");
            window.location.href = url;
        }

        function Clear() {

            if (confirm('您确定要重置吗？重置后傻瓜表单设计内容,与排序内容都将会被清除,系统将会使用bp实体类的属性展示.') == false)
                return;

            var mapdata = new Entity("BP.Sys.MapData", GetQueryString("EnsName"));
            mapdata.Delete();

            var mapAttrs = new Entities("BP.Sys.MapAttrs", "FK_MapData", GetQueryString("EnsName"));
            for (var i = 0; i < mapAttrs.length; i++) {
                mapAttrs[i].Delete();
            }

            //重置排序顺序
            window.location.href = window.location.href;
        }
        
        function FoolDesinger() {
            var url = "../../Admin/FoolFormDesigner/Designer.htm?FK_MapData=" + GetQueryString("EnsName") + "&FK_Flow=&FK_Node=0&IsFirst=1";
            window.open(url);
        }

        
    </script>
</head>
<body>
 <input type="button" value="保存" onclick="SaveCols()" />
    <input type="button" value="清空设置" onclick="Clear()" />
    <input type="button" value="启动傻瓜表单设计器" onclick="FoolDesinger()" />
    <input type="button" value="返回基本设置" onclick="Back()" />

    <table id="Table1" style="width: 96%;">
        <caption>
            设置显示的列</caption>
        <tr>
            <th>
                序号
            </th>
            <th>
                字段
            </th>
            <th>
                中文名
            </th>
            <th>
                宽度
            </th>
            <th>
                设置显示/隐藏
            </th>
            <th>
                顺序
            </th>
        </tr>
    </table>
   
</body>
</html>
